package insight.miescor.opp.domain;

import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;
import org.sormula.Database;
import org.sormula.SormulaException;
import org.sormula.Table;

public class Customer {
	private String id;
	private String name;
	private String sapId;

	public Customer() {

	}

	public Customer(JSONObject cusObj) throws JSONException {
		id = cusObj.has("id") ? cusObj.getString("id") : "";
		name = cusObj.has("name") ? cusObj.getString("name") : "";
		sapId = cusObj.has("sapId") ? cusObj.getString("sapId") : "";
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getSapId() {
		return sapId;
	}

	public void setSapId(String sapId) {
		this.sapId = sapId;
	}

	public static List<Customer> loadAll(Database database) throws Exception {
		Table<Customer> customerTable = database.getTable(Customer.class);
		return customerTable.selectAll();
	}

	public void save(Database database) throws SormulaException {
		Table<Customer> customerTable = database.getTable(Customer.class);
		customerTable.insert(this);
	}
}
